var ipconfig = "http://192.168.3.133:8080"//服务器ip地址
Page({
  data: {
    files: []
  },
  chooseImage: function (e) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      count:5,
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        console.log(res.tempFilePaths);
        var tempFilePaths=res.tempFilePaths;
          wx.uploadFile({
            url: ipconfig+'/wxRepairs',
            method: 'post',
            filePath: tempFilePaths[0],
            header:{
              'Cookie': wx.getStorageSync("session")//让session可以在其他地方获取
            },
            name: 'file',

          })
        that.setData({
          files: that.data.files.concat(res.tempFilePaths)
        });
      }
    })
  },

  previewImage: function (e) {
    wx.previewImage({
      current: e.currentTarget.id, // 当前显示图片的http链接
      urls: this.data.files // 需要预览的图片http链接列表
    })
  },
  formSubmit:function(e){
    var that=this;
    var repair_describe = e.detail.value.repair_describe;
    console.log('form发生了submit事件，携带数据为：'+repair_describe);
    
    wx.request({
      url: ipconfig+'/wxRepairSubmit',
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': wx.getStorageSync("session")
      },
      
      data:{
        repair_describe: repair_describe
        
      },
      success: function (res) {
        if (res.data == true) {
          repair_describe=null;
          wx.showToast({
            title: '上传成功',
            image: '../imgages/succeed.png',
          })
          setTimeout(function () {
            wx.redirectTo({
              url: '../subpage/repirs',
            })
          }, 3000)
          
          
        } else {
          wx.showToast({
            title: '上传失败',
            image: '../imgages/failure.png',

          })
        }
      }

    })

  }
});